import type { App } from 'vue'
import { ElLoading, ElScrollbar, ElButton, ElMessage } from 'element-plus'

export const setupElementMsg = (app: App<Element>) => {
  ;[ElLoading].forEach(app.use)
  ;[ElScrollbar, ElButton].forEach(c => app.component(c.name, c))

  // 配置 ElMessage 默认时长
  ;(['success', 'warning', 'error', 'info'] as const).forEach(type => {
    const original = ElMessage[type]
    ElMessage[type] = (options: any) => original(
      typeof options === 'string'
        ? { message: options, duration: 5000 }
        : { duration: 5000, ...options }
    )
  })
}
